package com.cjl.demo.data;

/**
 * <p>Description: </p>
 *
 * @ uthor chenjinliang
 * @ date: 2020/7/14
 */

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;



//按层遍历二叉树，输出到list
class Solution {
//    public List<List<Integer>> levelOrder(TreeNode root) {
//        //按层，存储node节点
//        List<List<TreeNode>> levelTreeNodList = new ArrayList<>();
//        List<TreeNode> currLevelNode = new ArrayList<>();
//        //遍历左右节点，将当前层级的所有左右节点，都放入下一个层级的List<TreeNode>中
//        //直到List<TreeNode>为空，说明没有子节点了
//        //遍历levelTreeNodeList.输出左右子节点；
//        return null;
//    }
//
//    class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//        TreeNode(int x) { val = x; }
//    }

    public static void main(String[] args) {
        //Scanner in = new Scanner(System.in);
        //int a = in.nextInt();
        //System.out.println(a);
        System.out.println("Hello World!");
    }
    //根，左，右
    public List<TreeNode> tree(TreeNode root){
        List<TreeNode> resultList= new ArrayList<TreeNode>();
        if(null == root){
            return resultList;
        }
        TreeNode current;

        List<TreeNode> list = new LinkedList<TreeNode>();
        list.add(0,root);
        while(!list.isEmpty()){
            current = list.remove(0);
            resultList.add(current);
            System.out.println(current.key );
            if(current.right != null){
                list.add(0,current.right);
            }
            if(current.left != null){
                list.add(0,current.left);
            }
        }
        return resultList;
    }

    class TreeNode{
        int key;
        TreeNode left;
        TreeNode right;
    }
}
